package cn.geodata.dataview.action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

import cn.geodata.dataview.Fire;
import cn.geodata.dataview.FireFactory;
import cn.geodata.service.user.UserInstance;

public class ImageSave {
	private static Logger Log = Logger.getLogger(ImageSave.class);
	
	private String id;
	private int path;
	private int row;
	private Date date;
	private String dir;
	private String source;
	private String sensor;
	private String note;
	private float cloud;
	private String quality;
	
	public String execute() throws Exception {
		Fire _data = new Fire();
		
		_data.setId(id);
		_data.setPath(path);
		_data.setRow(row);
		_data.setDate(date);
		_data.setSensor(sensor);
		_data.setSource(source);
		_data.setDir(dir);
		_data.setNote(note);
		_data.setCloud(cloud);
		_data.setQuality(quality);
		
		(new FireFactory()).save(_data, new UserInstance("dataview", "127.0.0.l"));
		
		return "success";
	}

	public void setPath(int path) {
		this.path = path;
	}

	public void setRow(int row) {
		this.row = row;
	}

	public void setDate(String date) throws ParseException {
		Log.info("Date:" + date);
		this.date = (new SimpleDateFormat("yyyy-MM-dd")).parse(date);
	}

	public void setDir(String dir) {
		this.dir = dir;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public void setSensor(String sensor) {
		this.sensor = sensor;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public void setId(String id) {
		if(id != null && id.length() > 0){
			this.id = id;
		}
		else{
			this.id = null;
		}
	}

	public void setCloud(float cloud) {
		this.cloud = cloud;
	}

	public void setQuality(String quality) {
		this.quality = quality;
	}
}
